/**
 * 
 */
package com.jie.eclipse.pan.gef.dialog;

import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.TableWrapLayout;

import com.jie.eclipse.pan.dao.QMDao;
import com.jie.eclipse.pan.editors.utils.PanImageHelper;
import com.jie.eclipse.pan.listener.PMouseListener;

/**
 * @author yanjie
 *
 */
public class OwnerDialog extends TitleAreaDialog{
	String fzr = "";
	String arg1 = "";
	String arg2= "";
	String arg3= "";
	String arg4= "";
	
	Combo reasignto = null;
	/**
	 * @param parentShell
	 */
	public OwnerDialog(Shell parentShell,String arg1,String arg2,String arg3,String arg4) {
		super(parentShell);
		this.arg1 = arg1;
		this.arg2 = arg2;
		this.arg3 = arg3;
		this.arg4 = arg4;
	}
	
	@Override
	protected Control createContents(Composite parent) {
		super.createContents(parent);
		this.getShell().setText(arg1);// 设置对话框标题栏
		this.setTitle(arg2);// 设置标题信息
		this.setMessage(arg3, IMessageProvider.INFORMATION);// 设置初始化对话框的提示信息
		//设置右侧的图片，一般为48*48大小
		this.setTitleImage(PanImageHelper.getInstance().getImage("icons/pan.jpg"));
		return parent;
	}
	
	@Override
	protected Point getInitialSize() {
		return new Point(300, 200);
	}
	
	@Override
	protected Control createDialogArea(Composite parent) {
		Color bgcolor = Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
		ScrolledForm  form = new ScrolledForm(parent, SWT.BORDER);
		form.setLayout(new GridLayout(1, false));
		form.setLayoutData(new GridData(GridData.FILL_BOTH));
		form.setAlwaysShowScrollBars(true);  
		form.setExpandHorizontal(true);
		form.setExpandVertical(true);
		FormToolkit tk = new FormToolkit(form.getDisplay()); 
		
		Composite body = form.getBody();
		body.setLayout( new TableWrapLayout());
		body.setBackground(bgcolor);
		body.setLayout(new GridLayout(2, false));
		body.setLayoutData(new GridData(GridData.FILL_BOTH));
		
		Label lb8 =tk.createLabel(body, arg4);
		lb8.setBackground(bgcolor);
		reasignto = new Combo(body, SWT.READ_ONLY);
		String[][] fzrs = QMDao.getInstance().getPanLogFZR(true);
		reasignto.setItems(fzrs[0]);
		reasignto.select(0);
		reasignto.setLayoutData(new GridData(100, 24));
		for (int i = 0; i < fzrs[1].length; i++) {
			reasignto.setData(String.valueOf(i), fzrs[1][i]);
		}
		return parent;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createButton(org.eclipse.swt.widgets.Composite, int, java.lang.String, boolean)
	 */
	@Override
	protected Button createButton(Composite parent, int id, String label,
			boolean defaultButton) {
		Image img = null;
		if(id == TitleAreaDialog.OK){
			label = "確定";
			img = PanImageHelper.getInstance().getImage("icons/icon_save.gif");
		}else if(id == TitleAreaDialog.CANCEL){
			label = "取消";
			img = PanImageHelper.getInstance().getImage("icons/icon_cancel.gif");
		}
		Button button = super.createButton(parent, id, label, defaultButton);
		button.setImage(img);
		button.addMouseListener(new PMouseListener(){
			@Override
			public void mouseUp(MouseEvent paramMouseEvent) {
				fzr = (String)reasignto.getData(String.valueOf(reasignto.getSelectionIndex()));
			}
		});
        return button;
	}
	
	/**
	 * @return the fzr
	 */
	public String getFzr() {
		return fzr;
	}

}
